Imports System
Imports System.Configuration
Imports System.Web.Configuration

Partial Class Usercontrols_Admin_MainPageSettings
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "



#End Region

#Region " Page Events "

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.MessageLabel = Me.uxMessagesLabel
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Me.Page.IsPostBack = False Then
            LoadSettings()
        End If

        Me.uxAdminPanel.Visible = ShowControls(SecurityMask.Admin, True)

    End Sub

#End Region

#Region " Save Data "

    Public Sub SaveSettings()
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim AppSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If Not (AppSettingsSection Is Nothing) Then

            If IsNothing(AppSettingsSection.Settings("DisplayUserActivity")) Then
                AppSettingsSection.Settings.Add("DisplayUserActivity", Me.uxDisplayUserActivityCheckBox.Checked)
            Else
                AppSettingsSection.Settings("DisplayUserActivity").Value() = Me.uxDisplayUserActivityCheckBox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayTags")) Then
                AppSettingsSection.Settings.Add("DisplayTags", Me.uxDisplayTagsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayTags").Value() = Me.uxDisplayTagsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayPosts")) Then
                AppSettingsSection.Settings.Add("DisplayPosts", Me.uxDisplayPostsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayPosts").Value() = Me.uxDisplayPostsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayBlogs")) Then
                AppSettingsSection.Settings.Add("DisplayBlogs", Me.uxDisplayBlogsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayBlogs").Value() = Me.uxDisplayBlogsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayEvents")) Then
                AppSettingsSection.Settings.Add("DisplayEvents", Me.uxDisplayEventsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayEvents").Value() = Me.uxDisplayEventsCheckbox.Checked
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayPages")) Then
                AppSettingsSection.Settings.Add("DisplayPages", Me.uxDisplayPagesCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayPages").Value() = Me.uxDisplayPagesCheckbox.Checked
			End If

			If IsNothing(AppSettingsSection.Settings("DisplaySlideShow")) Then
				AppSettingsSection.Settings.Add("DisplaySlideShow", Me.uxDisplaySlideShowCheckbox.Checked)
			Else
				AppSettingsSection.Settings("DisplaySlideShow").Value() = Me.uxDisplaySlideShowCheckbox.Checked
			End If

			If IsNothing(AppSettingsSection.Settings("DisplayLinks")) Then
				AppSettingsSection.Settings.Add("DisplayLinks", Me.uxDisplayLinksCheckbox.Checked)
			Else
				AppSettingsSection.Settings("DisplayLinks").Value() = Me.uxDisplayLinksCheckbox.Checked
			End If

            If IsNothing(AppSettingsSection.Settings("DisplayPolls")) Then
                AppSettingsSection.Settings.Add("DisplayPolls", Me.uxDisplayPollsCheckbox.Checked)
            Else
                AppSettingsSection.Settings("DisplayPolls").Value() = Me.uxDisplayPollsCheckbox.Checked
			End If

			If IsNothing(AppSettingsSection.Settings("DisplayRecentForumActivity")) Then
				AppSettingsSection.Settings.Add("DisplayRecentForumActivity", Me.uxDisplayRecentForumActivityCheckbox.Checked)
			Else
				AppSettingsSection.Settings("DisplayRecentForumActivity").Value() = Me.uxDisplayRecentForumActivityCheckbox.Checked
			End If

            configuration.Save()
        End If

    End Sub

    Public Sub SaveSettings(ByVal key As String, ByVal value As String)
        Dim configuration As Configuration = WebConfigurationManager.OpenWebConfiguration("~")
        Dim appSettingsSection As AppSettingsSection = CType(configuration.GetSection("appSettings"), AppSettingsSection)

        If Not (appSettingsSection Is Nothing) Then
            appSettingsSection.Settings(key).Value = value
            configuration.Save()
        End If
    End Sub

#End Region

#Region " Load Data "

    Public Sub LoadSettings()

        If Not (AppSettingsSection Is Nothing) Then
            If IsNothing(AppSettingsSection.Settings("DisplayUserActivity")) Then
                Me.uxDisplayUserActivityCheckBox.Checked = True
            Else
                Me.uxDisplayUserActivityCheckBox.Checked = AppSettingsSection.Settings("DisplayUserActivity").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayTags")) Then
                Me.uxDisplayTagsCheckbox.Checked = True
            Else
                Me.uxDisplayTagsCheckbox.Checked = AppSettingsSection.Settings("DisplayTags").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayPosts")) Then
                Me.uxDisplayPostsCheckbox.Checked = True
            Else
                Me.uxDisplayPostsCheckbox.Checked = AppSettingsSection.Settings("DisplayPosts").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayBlogs")) Then
                Me.uxDisplayBlogsCheckbox.Checked = True
            Else
                Me.uxDisplayBlogsCheckbox.Checked = AppSettingsSection.Settings("DisplayBlogs").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayEvents")) Then
                Me.uxDisplayEventsCheckbox.Checked = True
            Else
                Me.uxDisplayEventsCheckbox.Checked = AppSettingsSection.Settings("DisplayEvents").Value()
            End If

            If IsNothing(AppSettingsSection.Settings("DisplayPages")) Then
                Me.uxDisplayPagesCheckbox.Checked = True
            Else
                Me.uxDisplayPagesCheckbox.Checked = AppSettingsSection.Settings("DisplayPages").Value()
            End If

			If IsNothing(AppSettingsSection.Settings("DisplaySlideShow")) Then
				Me.uxDisplaySlideShowCheckbox.Checked = True
			Else
				Me.uxDisplaySlideShowCheckbox.Checked = AppSettingsSection.Settings("DisplaySlideShow").Value()
			End If

			If IsNothing(AppSettingsSection.Settings("DisplayLinks")) Then
				Me.uxDisplayLinksCheckbox.Checked = True
			Else
				Me.uxDisplayLinksCheckbox.Checked = AppSettingsSection.Settings("DisplayLinks").Value()
			End If

            If IsNothing(AppSettingsSection.Settings("DisplayPolls")) Then
                Me.uxDisplayPollsCheckbox.Checked = True
            Else
                Me.uxDisplayPollsCheckbox.Checked = AppSettingsSection.Settings("DisplayPolls").Value()
			End If

			If IsNothing(AppSettingsSection.Settings("DisplayRecentForumActivity")) Then
				Me.uxDisplayRecentForumActivityCheckbox.Checked = True
			Else
				Me.uxDisplayRecentForumActivityCheckbox.Checked = AppSettingsSection.Settings("DisplayRecentForumActivity").Value()
			End If

        End If

    End Sub

#End Region

#Region " Form Controls Events "

#End Region

#Region " Helpers and Methods "



#End Region

End Class
